package com.eddy.util;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

//全局配置类，配置跨域请求
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        /**
         * 1、addMapping 允许跨域路径： /** 都允许
         * 2、allowedOrigins 允许跨域的来源
         * 3、allowedMethods 允许跨域的请求/方法
         * 4、allowCredentials 是否允许证书
         * 5、maxAge 最大响应时间
         */
        registry.addMapping("/**")
                .allowedOrigins("http://localhost:8080","http://127.0.0.1:8080")
                .allowedMethods("GET","POST","PUT","OPTIONS","DELETE")
                .allowCredentials(true)
                .maxAge(3600);
    }
}
